package com.github.skystardust.lotteryex.lottery.item.imp.require;

import com.github.skystardust.lotteryex.lottery.item.RequireItem;
import com.github.skystardust.lotteryex.utils.SetExpFix;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.bukkit.entity.Player;

import java.util.Map;
import java.util.UUID;

@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class RequireItemExperience extends RequireItem<Integer> {

    public RequireItemExperience(Integer requireObject) {
        super(requireObject);
    }

    public RequireItemExperience(UUID uuid, Integer requireObject) {
        super(uuid, requireObject);
    }

    public RequireItemExperience(Map<String, Object> stringObjectMap) {
        super(stringObjectMap);
        setRequireObject(((Integer) stringObjectMap.get("requireObject")));
    }

    @Override
    public boolean hasRequireObject(Player player) {
        return SetExpFix.getTotalExperience(player) >= getRequireObject();
    }

    @Override
    public void takeItem(Player player) {
        SetExpFix.setTotalExperience(player, SetExpFix.getTotalExperience(player) - getRequireObject());
    }
}
